package controller.services.impl.reprodutivo;

import java.io.Serializable;
import java.util.List;

import model.interfaces.DAOFactory;
import model.interfaces.HibernateGenericDAO;
import model.vos.reprodutivo.Raca;

public class ImplRacaService implements Serializable {

	private static final long serialVersionUID = 7470367749457577631L;
	private DAOFactory daoFactory;
	private HibernateGenericDAO<Raca> daoRaca;
	private Raca raca;

	public Raca getRaca() {
		return raca;
	}

	public void setRaca(Raca raca) {
		this.raca = raca;
	}

	@SuppressWarnings("unchecked")
	public ImplRacaService() {
		this.daoFactory = DAOFactory.getDAOFactory(DAOFactory.HIBERNATE);
		this.raca = new Raca();
		this.daoRaca = (HibernateGenericDAO<Raca>) daoFactory.getRacaDAO();
	}

	public Raca pesquisarPorId(Serializable id) {
		try {
			Raca r = (Raca) this.daoRaca.pesquisarPorId(id);
			return r;
		} finally {
			this.daoFactory.encerrar();
		}

	}

	public List<Raca> listarTodos() {
		try {
			List<Raca> racas = this.daoRaca.listarTodos();
			return racas;

		} finally {
			this.daoFactory.encerrar();
		}
	}

	public Raca salvar(Raca raca) {
		this.daoFactory.iniciarTransacao();
		Raca r = (Raca) this.daoRaca.salvar(raca);
		this.daoFactory.encerrar();
		return r;
	}

	public void excluir(Raca r) {
		this.daoRaca.excluir(r);
		this.daoFactory.encerrar();
	}

	public void alterar(Raca r) {
		this.daoFactory.iniciarTransacao();
		this.daoRaca.alterar(r);
		this.daoFactory.encerrar();

	}

}
